#include "mainwindow.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QToolButton>
#include <QAction>
#include <QStackedWidget>
#include <QTableWidget>
#include <QApplication>
#include <QMenuBar>
#include <QMenu>
#include <QActionGroup>
#include <QStatusBar>

#include <QDebug>

#include "qlite/literibbonbar.h"
#include "qlite/litequickaccessbar.h"
#include "qlite/literibbontabbar.h"
#include "qlite/literibbonpage.h"
#include "qlite/literibbongroup.h"
#include "qlite/litetoolbar.h"
#include "qlite/litebar.h"

QLITE_USE_NAMESPACE

MainWindow::MainWindow(QWidget *parent)
    : LiteRibbonWindow(parent)
{
    QIcon icon(":/main/logo");
    LiteRibbonBar *ribbonBar = this->ribbonBar();

    LiteQuickAccessBar *quickAccessBar = ribbonBar->quickAccessBar();
    quickAccessBar->addAction(icon, tr("action 1"));
    quickAccessBar->addAction(icon, tr("action 2"));
    quickAccessBar->addAction(icon, tr("action 3"));
    quickAccessBar->addAction(icon, tr("action 4"));

    LiteToolBar *toolbar = ribbonBar->toolBar(LiteRibbonBar::ToolBarTopPosition);
    toolbar->addAction(icon, tr("top btn 1"));
    toolbar->addAction(icon, tr("top btn 2"));
    toolbar->addAction(icon, tr("top btn 3"));
    toolbar = ribbonBar->toolBar(LiteRibbonBar::ToolBarBottomPosition);
    toolbar->addAction(icon, tr("bottom btn 1"));
    toolbar->addAction(icon, tr("bottom btn 2"));
    toolbar->addAction(icon, tr("bottom btn 3"));

    /* pages and groups */
    LiteRibbonPage *page;
    LiteRibbonGroup *group;
    page = ribbonBar->addPage(icon, tr("page 1"));
    group = page->addGroup(tr("group 1"));
    group = page->addGroup(tr("group 2"));
    group = page->addGroup(tr("group 3"));
    group = page->addGroup(tr("group 4"));
    group = page->addGroup(tr("group 5"));

    ribbonBar->addPage(tr("page 2"));
    ribbonBar->addPage(tr("page 3"));
    ribbonBar->addPage(tr("page 4"));

    /* options */
    QAction *action = new QAction(icon, tr("options"));
    QMenu *menu = new QMenu(tr("options"));
    action->setMenu(menu);
    toolbar->addAction(action);

    action = new QAction(tr("Frameless"));
    action->setCheckable(true);
    connect(action, SIGNAL(toggled(bool)), this, SLOT(slotSetFrameless(bool)));
    menu->addAction(action);

    menu->addSeparator();

    action = new QAction(tr("TitleBar DarkIcon"));
    action->setCheckable(true);
    connect(action, SIGNAL(toggled(bool)), this, SLOT(slotSetDarkIcon(bool)));
    action->setChecked(true);
    menu->addAction(action);

    menu->addSeparator();

    QActionGroup *actionGroup = new QActionGroup(action);
    QAction *styleAction = menu->addAction(tr("Classic Style"));
    styleAction->setCheckable(true);
    styleAction->setData(QVariant(LiteRibbonBar::ClassicStyle));
    actionGroup->addAction(styleAction);
    styleAction = menu->addAction(tr("Merged Style"));
    styleAction->setCheckable(true);
    styleAction->setData(QVariant(LiteRibbonBar::MergedStyle));
    actionGroup->addAction(styleAction);
    connect(actionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeStyle(QAction *)));
    emit actionGroup->actions().at(0)->trigger();

//    menu->addSeparator();

    QWidget *cw = new QWidget();
    cw->setAutoFillBackground(true);
    QPalette palette = cw->palette();
    palette.setColor(QPalette::Window, QColor(100, 100, 0));
    cw->setPalette(palette);
    setCentralWidget(cw);

    setWindowTitle(tr("qlite ribbon demo"));
    resize(800, 300);
}

MainWindow::~MainWindow()
{

}

void MainWindow::slotChangeStyle(QAction *action)
{
    ribbonBar()->setRibbonStyle(static_cast<LiteRibbonBar::RibbonStyle>(action->data().toUInt()));
}

void MainWindow::slotSetDarkIcon(bool checked)
{
    ribbonBar()->liteBar()->setIconDark(checked);
}

void MainWindow::slotSetFrameless(bool frameless)
{
    setFrameless(frameless);
    show();
}

